package test.multi_thread;

import java.lang.management.ManagementFactory;

import log.debug.LogInterface;
import log.debug.LogTool;

public class SynchLiftOff implements Runnable{
	protected static final LogInterface mLog = new LogTool().getLogType();
	private static final String TAG = "SynchLiftOff";
	
	protected int countDown = 5;
	private static int taskCount = 0;
	private final int id = taskCount++;
	
	
	public SynchLiftOff() {
		super();
	}

	
	public SynchLiftOff(int countDown) {
		super();
		this.countDown = countDown;
	}
	
	public synchronized String status() {
		String info = "  ";
		info += "pidInfo==";
		info += ManagementFactory.getRuntimeMXBean().getName();
		info += "\t thread==";
		info += Thread.currentThread().getName();
		
		
		return "#" + id + "\t " + this + "\t" + "(" 
				+ (countDown>0 ? countDown : "LightOff") + "),"
				+" \t" + info;
	}


	public void run() {
				
			synchronized (LiftOff.class) {
				while(countDown-- > 0){
					mLog.i(TAG, status());
					Thread.yield();
				}
			}
	}
	
}
